/*
 * To change this template, choose Tools | Templates

 * and open the template in the editor.
 */

import java.net.*;
import java.io.*;
import java.util.ArrayList;







public class Main {


    public static String[][][]  values;



public Main() throws FileNotFoundException, IOException{


     ArrayList<String> companyNames = new ArrayList<String>();
            int numCompanies = 0;



            String path = ("infile.txt");


            BufferedReader file = new BufferedReader(new FileReader(path));
            String str = "";
            while ((str = file.readLine()) != null)
            {
                companyNames.add(str);
                numCompanies++;
            }
              values = new String[1][numCompanies][7];



            file.close();
     //Block 1 Goes Here
            for (int i =0;i <numCompanies; i++){
                URL mb =  new URL("http://finance.yahoo.com/q/ks?s=" + companyNames.get(i).toString() + "+Key+Statistics");
                URLConnection ucon = mb.openConnection();
                BufferedReader in2 = new BufferedReader(new InputStreamReader(ucon.getInputStream()));
                String s1;
                 s1 = in2.readLine();

              boolean  yes = true;
              boolean  pyes = true;
                //p = true;
              boolean  done = true;


                while (s1 != null && done == true)
                {
                    //Console.WriteLine(s);

 //===========================================================================================================================================
                	
                	
                	if (s1.contains("Current Ratio (mrq):") /*&& yes == true*/)
                    {

                        int index = s1.indexOf("Current Ratio (mrq):");
                        //Console.WriteLine(index + "\t" + s.Length);


                        String sub = s1.substring(index, (index + 100));



                        String[] info = sub.split(">");
                        String[] info2 = info[2].split("<");
                        String ratio = info2[0];
                        System.out.println("Current Ratio(LIQUIDITY) for the company " + companyNames.get(i).toString() + "  is  " + ratio);
                        //values[0][i][5] = ratio;
                        
                        
                    }
                	
                	
 //===============================================================================================================================
                	
                	
                	
                	if (s1.contains("Return on Assets (ttm):") /*&& yes == true*/)
                    {

                        int index = s1.indexOf("Return on Assets (ttm):");
                        //Console.WriteLine(index + "\t" + s.Length);


                        String sub = s1.substring(index, (index + 100));



                        String[] info = sub.split(">");
                        String[] info2 = info[2].split("<");
                        String ratio = info2[0];
                        System.out.println("Return on Assets(Profitability Indicator Ratios) for the company  " + companyNames.get(i).toString() + "  is  " + ratio);
                       // values[0][i][5] = ratio;
                        
                        
                    }	
                	
                
 //==============================================================================================================================
                	if (s1.contains("Return on Equity (ttm):") /*&& yes == true*/)
                    {

                        int index = s1.indexOf("Return on Equity (ttm):");
                        //Console.WriteLine(index + "\t" + s.Length);


                        String sub = s1.substring(index, (index + 100));



                        String[] info = sub.split(">");
                        String[] info2 = info[2].split("<");
                        String ratio = info2[0];
                        System.out.println("Return on Equity(Profitability Indicator Ratios) for the company  " + companyNames.get(i).toString() + "  is  " + ratio);
                       // values[0][i][5] = ratio;
                        
                        
                    }	   	
                
                	
 //===============================================================================================================================
                	if (s1.contains("Operating Cash Flow (ttm):") /*&& yes == true*/)
                    {

                        int index = s1.indexOf("Operating Cash Flow (ttm):");
                        //Console.WriteLine(index + "\t" + s.Length);


                        String sub = s1.substring(index, (index + 100));



                        String[] info = sub.split(">");
                        String[] info2 = info[2].split("<");
                        String ratio = info2[0];
                        System.out.println("Operating Cash Flow (Cash Flow Indicator Ratios) for the company  " + companyNames.get(i).toString() + "  is  " + ratio);
                       // values[0][i][5] = ratio;
                        
                        
                    }	   
//================================================================================================================================
                	if (s1.contains("Price/Book (mrq):") /*&& yes == true*/)
                    {

                        int index = s1.indexOf("Price/Book (mrq):");
                        //Console.WriteLine(index + "\t" + s.Length);


                        String sub = s1.substring(index, (index + 100));



                        String[] info = sub.split(">");
                        String[] info2 = info[2].split("<");
                        String ratio = info2[0];
                        System.out.println("Price/Book Ratio for the company (Investment Valuation Ratios)  " + companyNames.get(i).toString() + "  is  " + ratio);
                        values[0][i][5] = ratio;
                        
                        //yes = false;
                    }

//===================================================================================================================================
                	if (s1.contains("Price/Sales (ttm):") /*&& yes == true*/)
                    {

                        int index = s1.indexOf("Price/Sales (ttm):");
                        //Console.WriteLine(index + "\t" + s.Length);


                        String sub = s1.substring(index, (index + 100));



                        String[] info = sub.split(">");
                        String[] info2 = info[2].split("<");
                        String ratio = info2[0];
                        System.out.println("Price/Sales Ratio for the company (Investment Valuation Ratios)  " + companyNames.get(i).toString() + "  is  " + ratio);
                        values[0][i][5] = ratio;
                        
                        //yes = false;
                    }
	
                	
                	
//================================================================================================================================
                    
                	
                	if (s1.contains("Forward P/E") /*&& pyes == true*/)
                    {
                        //("Inside the loop for company : "  + companyNames[i].ToString());


                        int index = s1.indexOf("Forward P/E");
                        //Console.WriteLine(index + "\t" + s.Length);


                        String sub = s1.substring(index, (index + 200));




                        String[] info = sub.split(">");
                        String[] info2 = info[6].split("<");
                        String ratio = info2[0];
                        System.out.println("Forward P/E Ratio for the company  " + companyNames.get(i).toString() + "  is  " + ratio);
                        values[0][i][4] = ratio;

                       // pyes = false;
                    }


//==============================================================================================================================                    
                    
                	
                	if (s1.contains("Revenue Per Share (ttm):") && done == true)
                    {


                        int index = s1.indexOf("Revenue Per Share (ttm)");
                        //Console.WriteLine(index + "\t" + s.Length);


                        String sub = s1.substring(index, (index + 100));

                        
                        String[] info = sub.split(">");
                        String[] info2 = info[2].split("<");
                        String ratio = info2[0];
                        System.out.println("Revenue per Share for the company   " + companyNames.get(i).toString() + "  is  " + ratio);
                        values[0][i][6] = ratio;
                       

                      
                        done = false;
                    }






                    s1 = in2.readLine();




                }













            }

}

//Block 2 goes here

public static void main(String[] args) throws MalformedURLException, IOException {
        Main m=new Main();

    }

}

